(function(){
    let form = layui.form
    form.verify({
        pwd:[
            /^[\S]{6,12}$/
            ,'密码必须6到12位，且不能出现空格'
          ],

        newPwd: function (value){
            console.log(4444);
            let v = $('input[name=oldPwd]').val()
            if(value==v){
               return '新密碼不能与旧密码一致'
            }
        },

        rePwd: function (value){
            console.log(5555);
            // input和选择器不能有空格
            let v = $(' input[name=newPwd]').val()
            if(value!==v){
              return '新密码不相同'
            }
        }
    });

    $('form').on('submit',function(e){
        e.preventDefault()
        axios({
            method:'POST',
            url:'/my/updatepwd',
            data:$(this).serialize(),

        }).then(res=>{
            console.log(res);
            if(res.data.status!==0){
                return layui.layer.msg(res.data.message)
            }
            layui.layer.msg(res.data.message)
            $('form')[0].reset()
            setTimeout(() => {
                window.parent.location.href='../code/login.html'
            }, 2000);
        })

    })


})();